﻿using OdsServer.Common;
using OdsServer.Device.Tests;
using StructureMap;
using StructureMap.AutoMocking;
using System;

namespace OdsServer.Device.Core
{
    public static class IocHelper
    {
        public const string DebugProfile        = "Debug";
        public const string ProductionProfile   = "Release";

        public static void SetupIoc()
        {
            ObjectFactory.Configure(action =>
                {
                    action.Scan(sAction =>
                        {
                            sAction.WithDefaultConventions();
                        } );

                    action.Profile( DebugProfile, pAction =>
                        {
                            pAction.For<DeviceDataCallback>().UseSpecial(conf =>
                                {
                                    conf.IsThis( DeviceDataCallbackTests.deviceDataCallbackDelegate );
                                } );
                            pAction.For<IDriverInterop>().Use<DriverInterop>();
                            pAction.For<IDeviceInteropAI>().Use<DeviceInteropAI>();
                            pAction.For<IDeviceHandler>().Use<DeviceHandler>();
                        } );

                    action.Profile(ProductionProfile, pAction =>
                    {
                        pAction.For<IDriverInterop>().Use<DriverInterop>();
                        pAction.For<IDeviceInteropAI>().Use<DeviceInteropAI>();
                        pAction.For<IDeviceHandler>().Use<DeviceHandler>();
                    });
                } );
        }

        public static void SetProfile(string profile)
        {
            ObjectFactory.Profile = profile;
        }
    }
}